package yur.wedding.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer;
import yur.wedding.modules.sys.shiro.ShiroTag;

import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * Freemarker配置
 *
 * @Author: Yur
 * @Data:2021/11/8 23:06
 */
@Configuration
public class FreemarkerConfig {



    @Bean
    public FreeMarkerConfigurer freeMarkerConfigurer(ShiroTag shiroTag){
        FreeMarkerConfigurer configurer = new FreeMarkerConfigurer();
        //设置 Freemarker  的访问路径
        configurer.setTemplateLoaderPath("classpath:/templates");

        Map<String, Object> variables = new HashMap<>(1);

        //查看页面是否  有shiro  标签
        variables.put("shiro", shiroTag);

        //需要设置一个map 值传给  freemarker
        configurer.setFreemarkerVariables(variables);

        Properties settings = new Properties();
        settings.setProperty("default_encoding", "utf-8");
        settings.setProperty("number_format", "0.##");

        configurer.setFreemarkerSettings(settings);
        return configurer;
    }


}
